package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Sum;
import com.ruoyi.system.service.ISumService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考核管理Controller
 * 
 * @author pluto_xun@qq.com
 * @date 2020-12-11
 */
@Controller
@RequestMapping("/zzb/sum")
public class SumController extends BaseController
{
    private String prefix = "zzb/sum";

    @Autowired
    private ISumService sumService;

    @RequiresPermissions("zzb:sum:view")
    @GetMapping()
    public String sum()
    {
        return prefix + "/sum";
    }

    /**
     * 查询考核管理列表
     */
    @RequiresPermissions("zzb:sum:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Sum sum)
    {
        startPage();
        List<Sum> list = sumService.selectSumList(sum);
        return getDataTable(list);
    }

    /**
     * 导出考核管理列表
     */
    @RequiresPermissions("zzb:sum:export")
    @Log(title = "考核管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Sum sum)
    {
        List<Sum> list = sumService.selectSumList(sum);
        ExcelUtil<Sum> util = new ExcelUtil<Sum>(Sum.class);
        return util.exportExcel(list, "sum");
    }

    /**
     * 新增考核管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存考核管理
     */
    @RequiresPermissions("zzb:sum:add")
    @Log(title = "考核管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Sum sum)
    {
        return toAjax(sumService.insertSum(sum));
    }

    /**
     * 修改考核管理
     */
    @GetMapping("/edit/{sumId}")
    public String edit(@PathVariable("sumId") Long sumId, ModelMap mmap)
    {
        Sum sum = sumService.selectSumById(sumId);
        mmap.put("sum", sum);
        return prefix + "/edit";
    }

    /**
     * 修改保存考核管理
     */
    @RequiresPermissions("zzb:sum:edit")
    @Log(title = "考核管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Sum sum)
    {
        return toAjax(sumService.updateSum(sum));
    }

    /**
     * 删除考核管理
     */
    @RequiresPermissions("zzb:sum:remove")
    @Log(title = "考核管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sumService.deleteSumByIds(ids));
    }
}
